/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entities;

import java.util.ArrayList;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

/**
 *
 * @author Shane
 */
public class Player extends Entity {

    float damage;
    float attackSpeed;
    float timeSinceLastFire;
    float rotation;

    public Player(float x, float y, String imgLocation, float damage, float attackSpeed) throws SlickException {
        super(x, y, imgLocation);
        this.damage = damage;
        this.attackSpeed = attackSpeed;
    }

    public void update(GameContainer container, StateBasedGame game, int delta, ArrayList<Projectile> projectiles) throws SlickException {
        Input input = container.getInput();
        
        GetRotationFromMouse(input);
        
        timeSinceLastFire += .1;
        if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && timeSinceLastFire >= attackSpeed) {
            FireProjectile(projectiles);
            timeSinceLastFire = 0;
        }
    }

    public void GetRotationFromMouse(Input input) {
        
        float distX = input.getMouseX() - x - width/2;
        float distY = input.getMouseY() - y - height/2;

        rotation = (float) Math.toDegrees(Math.atan(distY / distX)) + 90;

        if (distX < 0) {
            rotation += 180;
        }
        image.setRotation(rotation);

    }

    public void FireProjectile(ArrayList<Projectile> projectiles) throws SlickException {
        Projectile tempProj = new Projectile(x+50, y+13, "data/arrow.png", 5.0f, 20.0f, rotation);
        projectiles.add(tempProj);
    }
}
